from google.appengine.ext import db
import logging

class Garden(db.Model):
    owner = db.UserProperty()
    name = db.StringProperty(required=True)
    description = db.StringProperty(multiline=True)
    address = db.PostalAddressProperty()
    geo_location = db.GeoPtProperty()

    @classmethod
    def get_garden_by_user(self, user):
        try:
            return Garden.all().filter('owner =', user).fetch(1)[0]
        except IndexError:
            logging.debug("couldn't find a garden for user %s" % user)
            return None

class Plant(db.Model):
    garden = db.ReferenceProperty(Garden)
    name = db.StringProperty(required=True)
    description = db.StringProperty(multiline=True)

class Report(db.Model):
    plant = db.ReferenceProperty(Plant)
    report = db.TextProperty()
    height_in_inches = db.IntegerProperty()
    width_in_inches = db.IntegerProperty()
    yield_pounds = db.IntegerProperty()
    yield_ounces = db.IntegerProperty()
    date = db.DateProperty(auto_now_add=True)

    
